package com.acargil.sudoku.view.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.acargil.sudoku.model.ISudokuEngine;
import com.acargil.sudoku.model.util.SudokuModelFactory;
import com.acargil.sudoku.view.ISudokuView;

public class GenerateListener implements ActionListener {
	
	private static ActionListener instance = null;
	private ISudokuEngine model;
	private ISudokuView view;
	
	public static ActionListener getInstance(ISudokuEngine model, ISudokuView view) {
		if (instance == null) {
			instance = new GenerateListener(model, view);
		}
			
		return instance;
	}
	
	protected GenerateListener(ISudokuEngine model, ISudokuView view) {
		this.model = model;
		this.view = view;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		model.clearAllCellValues();
		model = SudokuModelFactory.generateModel(model, SudokuModelFactory.DOUBLE_SHIFT);
		view.setAllCells(model.getAllCellValues());
	}
}
